#include "mytimer.h"

#include<QDebug>
#include <QTimer>
#include <QDateTime>
#include <QString>

#define TIMER_TIMEOUT   (1000)
extern int scp_torpedsim_timer_5ms;
extern int scp_torpedsim_timer_10ms;

MyTimer::MyTimer(QObject *parent)
    :QObject(parent)
{
    //5ms 定时器
    scp_torpedsim_pTimer_5ms = new QTimer(this);
    connect(scp_torpedsim_pTimer_5ms, SIGNAL(timeout()), this, SLOT(scp_torpedsim_pTimer_5ms_handleTimeout()));
    scp_torpedsim_pTimer_5ms->start(TIMER_TIMEOUT);

    //10ms定时器
    scp_torpedsim_pTimer_10ms = new QTimer(this);
    connect(scp_torpedsim_pTimer_10ms, SIGNAL(timeout()), this, SLOT(scp_torpedsim_pTimer_10ms_handleTimeout()));
    scp_torpedsim_pTimer_10ms->start(5*TIMER_TIMEOUT);
}

MyTimer::~MyTimer()
{

}

// 每次开启的时候将 scp_torpedsim_timer_5ms 置为1
void MyTimer::scp_torpedsim_pTimer_5ms_handleTimeout()
{
    qDebug()<<"timer 5ms 正在执行......";

    QDateTime dateTime(QDateTime::currentDateTime());
    QString qStr = dateTime.toString("yyy-MM-dd hh:mm::ss ddd");
    qDebug()<< qStr;

    scp_torpedsim_timer_5ms = 1;
    if(scp_torpedsim_pTimer_5ms->isActive()){
        //m_pTimer->stop();
    }
}

// 每次开启的时候将 scp_torpedsim_timer_10ms 置为1
void MyTimer::scp_torpedsim_pTimer_10ms_handleTimeout()
{
    qDebug()<<"timer 10ms 正在执行......";

    QDateTime dateTime(QDateTime::currentDateTime());
    QString qStr = dateTime.toString("yyy-MM-dd hh:mm::ss ddd");
    qDebug()<< qStr;

    scp_torpedsim_timer_10ms = 1;
    if(scp_torpedsim_pTimer_10ms->isActive()){
        //m_pTimer->stop();
    }
}
